home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectSound / EnumDevice / frmEnum.frm next >
Text File  |  2001-10-08  |  5KB  |  166 lines

  1. VERSION 5.00
  2. Begin VB.Form frmEnum 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "EnumDevices"
  5.    ClientHeight    =   1740
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   3960
  9.    Icon            =   "frmEnum.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   1740
  14.    ScaleWidth      =   3960
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.ComboBox cboCapture 
  17.       Height          =   315
  18.       Left            =   1320
  19.       Style           =   2  'Dropdown List
  20.       TabIndex        =   6
  21.       Top             =   840
  22.       Width           =   2535
  23.    End
  24.    Begin VB.ComboBox cboSound 
  25.       Height          =   315
  26.       Left            =   1320
  27.       Style           =   2  'Dropdown List
  28.       TabIndex        =   5
  29.       Top             =   420
  30.       Width           =   2535
  31.    End
  32.    Begin VB.CommandButton cmdExit 
  33.       Cancel          =   -1  'True
  34.       Caption         =   "E&xit"
  35.       Height          =   315
  36.       Left            =   2880
  37.       TabIndex        =   4
  38.       Top             =   1260
  39.       Width           =   975
  40.    End
  41.    Begin VB.CommandButton cmdCreate 
  42.       Caption         =   "&Create"
  43.       Default         =   -1  'True
  44.       Height          =   315
  45.       Left            =   120
  46.       TabIndex        =   3
  47.       Top             =   1260
  48.       Width           =   975
  49.    End
  50.    Begin VB.Label Label1 
  51.       BackStyle       =   0  'Transparent
  52.       Caption         =   "Capture Device:"
  53.       Height          =   255
  54.       Index           =   2
  55.       Left            =   120
  56.       TabIndex        =   2
  57.       Top             =   900
  58.       Width           =   1215
  59.    End
  60.    Begin VB.Label Label1 
  61.       BackStyle       =   0  'Transparent
  62.       Caption         =   "Sound Device:"
  63.       Height          =   255
  64.       Index           =   1
  65.       Left            =   120
  66.       TabIndex        =   1
  67.       Top             =   480
  68.       Width           =   1215
  69.    End
  70.    Begin VB.Label Label1 
  71.       BackStyle       =   0  'Transparent
  72.       Caption         =   "This sample shows how to enumerate devices."
  73.       Height          =   255
  74.       Index           =   0
  75.       Left            =   120
  76.       TabIndex        =   0
  77.       Top             =   60
  78.       Width           =   4455
  79.    End
  80. End
  81. Attribute VB_Name = "frmEnum"
  82. Attribute VB_GlobalNameSpace = False
  83. Attribute VB_Creatable = False
  84. Attribute VB_PredeclaredId = True
  85. Attribute VB_Exposed = False
  86. Option Explicit
  87.  
  88. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  89. '
  90. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  91. '
  92. '  File:       frmEnum.frm
  93. '
  94. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  95. Private dx As New DirectX8
  96. Private dsEnum As DirectSoundEnum8
  97. Private dscEnum As DirectSoundEnum8
  98. Private ds As DirectSound8
  99. Private dsc As DirectSoundCapture8
  100.  
  101. Private Sub cmdCreate_Click()
  102.     On Error GoTo FailedCreate
  103.         
  104.     'Create a DirectSound object
  105.     Set ds = dx.DirectSoundCreate(dsEnum.GetGuid(cboSound.ListIndex + 1))
  106.     Set ds = Nothing 'We should get rid of it now, since we don't want to fail
  107.                      'If the machine doesn't support full duplex
  108.                      
  109.     'Create a Capture Buffer
  110.     Set dsc = dx.DirectSoundCaptureCreate(dscEnum.GetGuid(cboCapture.ListIndex + 1))
  111.     Set dsc = Nothing 'Release it
  112.     'Notify the user we succeeded
  113.     MsgBox "DirectSound8 and DirectSoundCapture8 object creation succeeded.", vbOKOnly Or vbInformation, "Success"
  114.     Exit Sub
  115.     
  116. FailedCreate:
  117.     'Notify the user we failed
  118.     MsgBox "DirectSound8 and DirectSoundCapture8 object creation failed.", vbOKOnly Or vbInformation, "Failure"
  119. End Sub
  120.  
  121. Private Sub cmdExit_Click()
  122.     'We're done exit
  123.     Unload Me
  124. End Sub
  125.  
  126. Private Sub CleanUp()
  127.     Set dscEnum = Nothing
  128.     Set dsEnum = Nothing
  129.     Set dx = Nothing
  130. End Sub
  131.  
  132. Private Sub Form_Load()
  133.     'Enum the devices and load them into the box
  134.     LoadEnum
  135. End Sub
  136.  
  137. Private Sub LoadEnum()
  138.     Dim lCount As Long
  139.     
  140.     On Error GoTo FailedEnum
  141.     Set dsEnum = dx.GetDSEnum
  142.     Set dscEnum = dx.GetDSCaptureEnum
  143.     
  144.     'Add each description to the combo box
  145.     For lCount = 1 To dsEnum.GetCount
  146.         cboSound.AddItem dsEnum.GetDescription(lCount)
  147.     Next
  148.     'Add each description to the combo box
  149.     For lCount = 1 To dscEnum.GetCount
  150.         cboCapture.AddItem dscEnum.GetDescription(lCount)
  151.     Next
  152.     On Error Resume Next
  153.     'Select the first item in each combo box
  154.     cboCapture.ListIndex = 0
  155.     cboSound.ListIndex = 0
  156.     Exit Sub
  157.     
  158. FailedEnum:
  159.     MsgBox "Error enumerating DirectSound devices. " & vbCrLf & "Sample will now exit.", vbOKOnly Or vbInformation, "DirectSound Sample"
  160.     Unload Me
  161. End Sub
  162.  
  163. Private Sub Form_Unload(Cancel As Integer)
  164.     CleanUp
  165. End Sub
  166.